#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "formsqlconnect.h"
#include "ui_formsqlconnect.h"
#include "formmysql.h"
#include "ui_formmysql.h"
#include "formmongodb.h"
#include "ui_formmongodb.h"
#include "formredis.h"
#include "ui_formredis.h"
#include "formgaussdb.h"
#include "ui_formgaussdb.h"
#include<QTableView>
#include<QStandardItem>
#include<QStandardItemModel>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //这一段设置用于创建数据库的初始表格样式，我以前后注释符归为一段
    QStandardItemModel *page_0tableforcredatabase= new QStandardItemModel(ui->tableViewCreatedatabase);   //建立这个变量，是一个表的模板
    page_0tableforcredatabase->setHorizontalHeaderItem(0,new QStandardItem("数据库名"));    //设置字段名
    page_0tableforcredatabase->setHorizontalHeaderItem(1,new QStandardItem("数据文件路径"));
    page_0tableforcredatabase->setHorizontalHeaderItem(2,new QStandardItem("日志文件路径"));
    page_0tableforcredatabase->setRowCount(1);     //设置行数
    ui->tableViewCreatedatabase->setModel(page_0tableforcredatabase);     //用setmodel将上面的模板应用到tableview上
    ui->stackedWidget->hide();       //先隐藏这个stackedwidget
    //

    //创建用于创建表的表
    QStandardItemModel *page_1tableforcretable=new QStandardItemModel(ui->tableViewCreatetable);
    page_1tableforcretable->setHorizontalHeaderItem(0,new QStandardItem("字段名"));
    page_1tableforcretable->setHorizontalHeaderItem(1,new QStandardItem("数据类型"));
    page_1tableforcretable->setHorizontalHeaderItem(2,new QStandardItem("数据长度"));
    page_1tableforcretable->setHorizontalHeaderItem(3,new QStandardItem("空"));
    page_1tableforcretable->setHorizontalHeaderItem(4,new QStandardItem("主键"));
    page_1tableforcretable->setHorizontalHeaderItem(5,new QStandardItem("外键/表名"));
    page_1tableforcretable->setHorizontalHeaderItem(6,new QStandardItem("外键/字段"));
    page_1tableforcretable->setRowCount(1);
    ui->tableViewCreatetable->setModel(page_1tableforcretable);
    //

    //创建用于按需查询的表
    QStandardItemModel *page_2tabelforselect=new QStandardItemModel(ui->tableViewSelect);
    page_2tabelforselect->setHorizontalHeaderItem(0,new QStandardItem("查询字段"));
    page_2tabelforselect->setHorizontalHeaderItem(1,new QStandardItem("查询来源"));
    page_2tabelforselect->setHorizontalHeaderItem(2,new QStandardItem("满足条件"));
    page_2tabelforselect->setRowCount(1);
    ui->tableViewSelect->setModel(page_2tabelforselect);
    //

    //创建用于更新数据的表
    QStandardItemModel *page_3tableforuqdatedata=new QStandardItemModel(ui->tableViewSelect);
    page_3tableforuqdatedata->setHorizontalHeaderItem(0,new QStandardItem("表名"));
    page_3tableforuqdatedata->setHorizontalHeaderItem(1,new QStandardItem("更新字段"));
    page_3tableforuqdatedata->setHorizontalHeaderItem(2,new QStandardItem("更新值"));
    page_3tableforuqdatedata->setHorizontalHeaderItem(3,new QStandardItem("条件"));
    page_3tableforuqdatedata->setRowCount(1);
    ui->tableViewUpdatedata->setModel(page_3tableforuqdatedata);
    //
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_actionSQLServer_triggered()    //点击主窗口的连接下的SQLSERVER，打开连接窗口
{
    Formsqlconnect *sqlconnect= new Formsqlconnect;
    sqlconnect->show();
}

void MainWindow::on_actionMysql_triggered()       //点击主窗口的连接下的Mysql，打开连接窗口
{
    Formmysql *mysqlconnect= new Formmysql;
    mysqlconnect->show();
}

void MainWindow::on_actionMongoDB_triggered()     //点击主窗口的连接下的Mongodb，打开连接窗口
{
    Formmongodb *mongodbconnect=new Formmongodb;
    mongodbconnect->show();
}

void MainWindow::on_actionRedis_triggered()        //点击主窗口的连接下的Redis，打开连接窗口
{
    Formredis *redisconnect=new Formredis;
    redisconnect->show();
}

void MainWindow::on_actionGaussDB_triggered()       //点击主窗口的连接下的GaussDB，打开连接窗口
{
    Formgaussdb *gaussdbconnect=new Formgaussdb;
    gaussdbconnect->show();
}

void MainWindow::on_actionCreatedatabase_triggered()     //为菜单“新建-数据库”添加事件，打开对应界面
{
    ui->tableViewCreatedatabase->setColumnWidth(0,200);   //设置列宽
    ui->tableViewCreatedatabase->setRowHeight(0,60);      //设置行高
    ui->tableViewCreatedatabase->setColumnWidth(1,500);
    ui->tableViewReturnviewgraph->setRowHeight(1,60);
    ui->tableViewCreatedatabase->setColumnWidth(2,500);
    ui->tableViewCreatedatabase->setRowHeight(2,60);
    ui->stackedWidget->show();                 //显示配件只能一级一级地展示
    ui->stackedWidget->setCurrentIndex(0);     //stackedwidget可以显示多页面，通过参数找到指定页面，0是第一页
}

void MainWindow::on_actionCreatetable_triggered()    //为菜单“新建-表”添加事件，打开对应界面
{
    ui->tableViewCreatetable->setColumnWidth(0,180);
    ui->tableViewCreatetable->setRowHeight(0,60);
    ui->tableViewCreatetable->setColumnWidth(1,180);
    ui->tableViewCreatetable->setRowHeight(1,60);
    ui->tableViewCreatetable->setColumnWidth(2,180);
    ui->tableViewCreatetable->setRowHeight(2,60);
    ui->tableViewCreatetable->setColumnWidth(3,150);
    ui->tableViewCreatetable->setRowHeight(3,60);
    ui->tableViewCreatetable->setColumnWidth(4,150);
    ui->tableViewCreatetable->setRowHeight(4,60);
    ui->tableViewCreatetable->setColumnWidth(5,180);
    ui->tableViewCreatetable->setRowHeight(5,60);
    ui->tableViewCreatetable->setColumnWidth(6,180);
    ui->tableViewCreatetable->setRowHeight(6,60);
    ui->stackedWidget->show();
    ui->stackedWidget->setCurrentIndex(1);
}

void MainWindow::on_actionSelectdepend_triggered()  //为菜单“查询-按需查询”添加事件，打开对应界面
{
    ui->tableViewSelect->setColumnWidth(0,300);
    ui->tableViewSelect->setColumnWidth(1,450);
    ui->tableViewSelect->setColumnWidth(2,450);
    ui->tableViewSelect->setRowHeight(0,60);
    ui->stackedWidget->show();
    ui->stackedWidget->setCurrentIndex(2);
}

void MainWindow::on_actionUpdatedata_triggered()    //为菜单“更新-更新数据”添加事件，打开对应界面
{
    ui->tableViewUpdatedata->setColumnWidth(0,300);
    ui->tableViewUpdatedata->setColumnWidth(1,300);
    ui->tableViewUpdatedata->setColumnWidth(2,300);
    ui->tableViewUpdatedata->setColumnWidth(3,300);
    ui->tableViewUpdatedata->setRowHeight(0,60);
    ui->stackedWidget->show();
    ui->stackedWidget->setCurrentIndex(3);
}

void MainWindow::on_actionDeleteobject_triggered()   //为菜单“删除-删除对象”添加事件，打开对应界面
{
    ui->stackedWidget->show();
    ui->stackedWidget->setCurrentIndex(6);
}
